package com.qf.controller;

import com.qf.service.CartService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/cart")
@CrossOrigin
public class CartController {
    @Autowired
    CartService cartService;

    @GetMapping("/findAll")
    public ResultMsg findAll(HttpServletRequest request) {
        return cartService.findAll(request);
    }

    @GetMapping("/addNewGoods")
    public ResultMsg addNewGoods(Integer goodsId, HttpServletRequest request) {
        return cartService.addGoods(goodsId, request);
    }

    @PostMapping("/modifyGoodsNum")
    public ResultMsg modifyGoodsNum(@RequestBody Map<String, Integer> map, HttpServletRequest request) {
        return cartService.modifyGoodsNum(map.get("goodsId"), map.get("goodsNum"), request);
    }

    @GetMapping("/deleteGoods")
    public ResultMsg deleteGoods(Integer cartId) {
        return cartService.removeGoods(cartId);
    }
}
